package teamGiga.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import teamGiga.bean.ShowingBean;
import teamGiga.dao.MovieDao;
import action.servlet.ActionForWard;

public class JsonslistAction extends Action{
	private String path;
	private boolean redirect;
	public JsonslistAction(String path, boolean redirect) {
		super();
		this.path = path;
		this.redirect = redirect;
	}
	public JsonslistAction() {
		super();
	}
	@Override
	public ActionForWard execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			List<ShowingBean>slist=MovieDao.getShowing();
			StringBuffer sb=new StringBuffer();
			sb.append("[");
			for (int i = 0; i < slist.size(); i++) {
				ShowingBean bean=slist.get(i);
				sb.append("{");
				sb.append("\"sno\":\"" + bean.getSno() + "\",");
				sb.append("\"tno\":\"" + bean.getTno() + "\",");
				sb.append("\"tname\":\"" + bean.getTname() + "\",");
				sb.append("\"taddress\":\"" + bean.getTaddress() + "\",");
				sb.append("\"trnum\":\"" + bean.getTrnum() + "\",");
				sb.append("\"showdate\":\"" + bean.getShowdate() + "\",");
				sb.append("\"showtime\":\"" + bean.getShowtime() + "\",");
				sb.append("\"mno\":\"" + bean.getMno() + "\",");
				sb.append("\"mname\":\"" + bean.getMname() + "\",");
				sb.append("\"scapacity\":\"" + bean.getScapacity() + "\"");
				if (i < (slist.size() - 1)) {
					sb.append("},");
				} else {
					sb.append("}");
				}
			}
			sb.append("]");
			request.setAttribute("sb", sb);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return new ActionForWard(path, redirect);
	}
	
}
